# -*- coding: utf-8 -*-
# owner: shenyi

# src/core/config.py
import os
from pathlib import Path
from dotenv import load_dotenv

def get_default_env_path() -> Path:
    """统一定义默认配置文件路径"""
    home = Path(os.environ.get("CLOUD_KIT_HOME", Path.home()))
    return home / ".cloudkit" / ".env"

class Config:
    def __init__(self, env_path: str | Path | None = None, override: bool = False):
        if env_path is None:
            self.env_path = get_default_env_path()
        else:
            self.env_path = Path(env_path)

        if self.env_path.exists():
            load_dotenv(dotenv_path=self.env_path, override=override)
        # 否则只用 os.environ（生产环境常见）

    def get(self, key: str, default=None) -> str | None:
        return os.environ.get(key, default)
